package com.xmlrpc.wordpress;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;

public class Main {
	public static void main(String[] args){
		
		XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
	    try {
			config.setServerURL(new URL("http://localhost:8099/wp/xmlrpc.php"));
		} catch (MalformedURLException e) {
	
			e.printStackTrace();
		}
	    XmlRpcClient client = new XmlRpcClient();
	    client.setConfig(config);
	    Map content = new HashMap();
	    	content.put("post_title", "测试");
	    	content.put("post_type", "post");
	    Map custom_fields = new HashMap();
	    custom_fields.put("key", "video_url_value");
	    custom_fields.put("value", "cedafdfas");
	    List array = new ArrayList();
	    array.add(custom_fields);
	    content.put("custom_fields",array);
	    content.put("post_status", "publish");
	    Object[] params = new Object[]{"1", "admin", "123456", content};
	    try {
			String result = (String) client.execute("wp.newPost", params);
			System.out.println("Message is "+result);
		} catch (XmlRpcException e) {
			
			e.printStackTrace();
		}
	}


}
